package uk.org.landeg.euler.problems;

import java.util.Arrays;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;
import uk.org.landeg.euler.problems.lib.NumbersLib;

public class Problem048 extends AbstractProblem{
	public static void main(String[] args) {
		ProblemLauncher launcher = new ProblemLauncher(new Problem048());
		launcher.solve();		
	}
	
	@Override
	public String getDescription() {
		return "Find the last ten digits of 11 + 22 + ... + 10001000.";
	}
	@Override
	public Integer getProblemNumber() {
		return 48;
	}
	@Override
	public Object solve() {
		int digits[] = new int [10];
		int currentDigits[] = new int [10];
//		digits[9] = 9998;
//		NumbersLib.normalizeDigitArray(digits);
//		System.out.println(Arrays.toString(digits));
		Arrays.fill(digits, 0);
		for (int i = 1 ; i <= 1000 ; i++) {
			Arrays.fill(currentDigits, 0);
			currentDigits[currentDigits.length-1] = i;
			NumbersLib.normalizeDigitArray(currentDigits);
			for (int m = 2; m <= i ; m++) {
				for (int d = 0 ; d<digits.length ;d++) {
					currentDigits[d] *= i;
				}
				NumbersLib.normalizeDigitArray(currentDigits);
			}
			for (int d = 0 ; d<digits.length ;d++) {
				digits[d] += currentDigits[d];
			}
			NumbersLib.normalizeDigitArray(digits);
		}
		return Arrays.toString(digits);
	}
	
	
}
